package states

import (
	"go_server/game_server/api/service"
	"go_server/game_server/event_manager"
	"go_server/game_server/event_manager/event_data"
	"go_server/zinx/zlog"
)

const (
	CLICK_TYPE1 = 1 // 杂物配置
	CLICK_TYPE2 = 2 // 收集食物配置
)

type StatesService struct {
	service.AbsService

	GetStateList *GetStateListApi
	Weed         *WeedApi
	SaveTimeLine *SaveTimeLineApi
	CollectFood  *CollectFoodApi
	SaveNewGuide *SaveNewGuideApi
	BuildRescue  *BuildRescueApi

	eventMethods map[event_data.EventType]func(event event_data.IEvent)
}

var (
	ServiceObj *StatesService
)

func init() {
	ServiceObj = &StatesService{
		GetStateList: &GetStateListApi{},
		Weed:         &WeedApi{},
		SaveTimeLine: &SaveTimeLineApi{},
		CollectFood:  &CollectFoodApi{},
		SaveNewGuide: &SaveNewGuideApi{},
		BuildRescue:  &BuildRescueApi{},

		eventMethods: make(map[event_data.EventType]func(event event_data.IEvent)),
	}

	event_manager.EventManagerObj.AddServiceEvent(event_data.LoginEvent, onLoginEvent, ServiceObj) //监听登录事件，测试
}

func (s *StatesService) GetModuleName() string {
	return "states"
}

func (s *StatesService) GetEventHandleFunc(eventType event_data.EventType) (func(event event_data.IEvent), bool) {
	eventFunc, ok := s.eventMethods[eventType]
	if !ok {
		zlog.Errorf("GetEventHandleFunc Err!!! method not found!! eventType: %d", eventType)
		return nil, false
	}
	return eventFunc, true
}

func (s *StatesService) GetEventMap() map[event_data.EventType]func(event event_data.IEvent) {
	return s.eventMethods
}

func onLoginEvent(event event_data.IEvent) {
	/*conn := event.GetRoleConn()
	roleId, ok := event.GetRoleId()
	if !ok {
		return
	}

	ServiceObj.BuildRescue.TestHandle(roleId, conn)*/
}
